package com.loop.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @author zhangxiaolu
 * @since 2023-09-03 21:14
 */
public class NIOFileChannel04 {

    public static void main(String[] args) throws Exception {
        // 创建流
        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\BreakTheLoop\\Pictures\\211808-zbjwiassrk.png");
        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\BreakTheLoop\\Pictures\\2.png");

        // 获取流中的channel
        FileChannel fileChannel = fileInputStream.getChannel();
        FileChannel fileChannel1 = fileOutputStream.getChannel();

        // 使用transferTo方法进行复制
        fileChannel.transferTo(0, fileChannel.size(), fileChannel1);
        fileChannel.close();
        fileChannel1.close();
    }
}
